package com.gaogzhen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaogzhen.domain.UserAddress;
import com.gaogzhen.mapper.UserAddressMapper;
import com.gaogzhen.service.UserAddressService;
import org.springframework.stereotype.Service;
/**
* @description ${description}
* @author Administrator
* @date 2022-06-07 11:46
* @version 1.0
*/
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements UserAddressService{

    @Override
    public Page<UserAddress> findByPage(Page<UserAddress> page, Long userId) {
        page.addOrder(OrderItem.desc("last_update_time"));
        return page(page, Wrappers.lambdaQuery(UserAddress.class)
                .eq(UserAddress::getUserId, userId)
        );

    }

    @Override
    public UserAddress getCoinAddress(Long userId, Long coinId) {
        return getOne(new LambdaQueryWrapper<UserAddress>()
                        .eq(UserAddress::getUserId, userId)
                        .eq(UserAddress::getCoinId, coinId)
        );
    }
}
